import * as echarts from 'echarts';
export function topChart(echartData, title) {
    var xData = ['0-59', '60-65', '66-69', '70-75', '76-79', '80-85', '86-89', '90-95', '96-100']
    return {
        title:{
            text: title
        },
        "tooltip": {
            "trigger": "axis",
            "axisPointer": {
                "type": "shadow",
                textStyle: {
                    color: "#fff"
                }

            },
        },
        "grid": {
            "borderWidth": 0,
            top: 60,
            bottom: 60,
            left: 40,
            right: 40,
            textStyle: {
                color: "#fff"
            }
        },
        "calculable": true,
        "xAxis": [{
            "type": "category",
            axisLine: {
                lineStyle: {
                    color: 'rgba(193, 207, 220, 1)',
                    width: 1
                }
            },
            axisTick: {
                show: false
            },
            axisLabel: {
                interval: 0,
                textStyle: {
                    color: 'rgba(0, 0, 0, 0.72)',
                    fontSize: 14
                },
            },
            "splitLine": {
                "show": false
            },
            "splitArea": {
                "show": false
            },
            "data": xData,
        }],
        yAxis: [{
            type: 'value',
            // minInterval: 1000,
            axisTick: {
                show: false
            },
            axisLine: {
                show: false,
            },
            axisLabel: {
                textStyle: {
                    color: 'rgba(0, 0, 0, 0.72)',
                    fontSize: 15
                },
            },
            splitLine: {
                show: true,
                lineStyle: {
                    color: 'rgba(193, 207, 220, 1)',
                    // type: 'dashed'
                }
            },
        }],
        "series": [{
            "name": "分布情况",
            "type": "bar",
            "barMaxWidth": 26,
            "barGap": "10%",
            itemStyle: {
                normal: {
                    color: (params) => {
                        let colors = [new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: 'rgba(254, 174, 162, 1)',
                        },
                        {
                            offset: 1,
                            color: 'rgba(253, 114, 112, 1)',
                        },
                        ]), new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: 'rgba(251, 169, 128, 1)',
                        },
                        {
                            offset: 1,
                            color: 'rgba(247, 203, 107, 1)',
                        },
                        ]), new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: 'rgba(251, 169, 128, 1)',
                        },
                        {
                            offset: 1,
                            color: 'rgba(247, 203, 107, 1)',
                        },
                        ]), new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: 'rgba(123, 200, 255, 1)',
                        },
                        {
                            offset: 1,
                            color: 'rgba(53, 157, 245, 1)',
                        },
                        ]), new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: '#CFF4D2',
                        },
                        {
                            offset: 1,
                            color: '#78E495',
                        },
                        ]), new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: '#CFF4D2',
                        },
                        {
                            offset: 1,
                            color: '#78E495',
                        },
                        ]), new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: '#CFF4D2',
                        },
                        {
                            offset: 1,
                            color: '#78E495',
                        },
                        ]), new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: '#CFF4D2',
                        },
                        {
                            offset: 1,
                            color: '#78E495',
                        },
                        ]), new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: '#CFF4D2',
                        },
                        {
                            offset: 1,
                            color: '#78E495',
                        },
                        ])]
                        return colors[params.dataIndex]
                    },
                    barBorderRadius: [30, 30, 0, 0] //圆角大小
                },
            },
            label: {
                normal: {
                    show: true,
                    position: "top",
                    formatter: function (data) {
                        return '{a' + data.dataIndex + '|' + data.data + '}';

                    },
                    rich: {
                        a0: {
                            color: 'rgba(220, 85, 69, 1)',
                            fontSize: 16,
                            fontFamily: 'DIN',
                            fontWeight: 'bold'
                        },
                        a1: {
                            color: 'rgba(250, 157, 0, 1)',
                            fontSize: 16,
                            fontFamily: 'DIN',
                            fontWeight: 'bold'
                        },
                        a2: {
                            color: 'rgba(250, 157, 0, 1)',
                            fontSize: 16,
                            fontFamily: 'DIN',
                            fontWeight: 'bold'
                        },
                        a3: {
                            color: 'rgba(73, 112, 200, 1)',
                            fontSize: 16,
                            fontFamily: 'DIN',
                            fontWeight: 'bold'
                        },
                        a4: {
                            color: '#78E495',
                            fontSize: 16,
                            fontFamily: 'DIN',
                            fontWeight: 'bold'
                        },
                        a5: {
                            color: '#78E495',
                            fontSize: 16,
                            fontFamily: 'DIN',
                            fontWeight: 'bold'
                        },
                        a6: {
                            color: '#78E495',
                            fontSize: 16,
                            fontFamily: 'DIN',
                            fontWeight: 'bold'
                        },
                        a7: {
                            color: '#78E495',
                            fontSize: 16,
                            fontFamily: 'DIN',
                            fontWeight: 'bold'
                        },
                        a8: {
                            color: '#78E495',
                            fontSize: 16,
                            fontFamily: 'DIN',
                            fontWeight: 'bold'
                        }
                    }
                },
            },
            "data": echartData,
        }
        ]
    }
}